package com.x.Part1_Comparable;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * ClassName: ComparableTest
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.03.28 20:32
 */
public class ComparableTest {
    @Test
    public void test1(){
        String[] str = new String[]{"Bom","Ais","Bony"};

        Arrays.sort(str);

        for(int i=0;i<str.length;i++){
            System.out.println(str[i]);
        }
    }
    @Test
    public void test2(){
        Phone[] phones = new Phone[3];

        phones[0] = new Phone("HuaWei", 7999);
        phones[1] = new Phone("OPPO", 6999);
        phones[2] = new Phone("vivo", 6999);

        Arrays.sort(phones);//java.lang.ClassCastException:Phone类不能转化成java.lang.Comparable类

        for(int i = 0; i < phones.length; i++){
            System.out.println(phones[i]);
        }
    }


}
